package com.googlecode.shapeline.web;

import java.io.IOException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class LogoutAction extends DispatchAction {
	private static final org.apache.log4j.Logger log = org.apache.log4j.LogManager.getLogger(LogoutAction.class);

	@SuppressWarnings("unchecked")
	public ActionForward execute(
			ActionMapping mapping, 
			ActionForm form, 
			HttpServletRequest request,
			HttpServletResponse response)
			throws IOException, ServletException {

		log.debug("user logout");
		Enumeration<String> names = request.getSession(true).getAttributeNames();
		while (names.hasMoreElements()) {
			String name = names.nextElement();
			log.debug("remove session : " + name);
			request.getSession(true).removeAttribute(name);
		}
		return mapping.findForward("login");
	}
}
